<template>
  <div class="ruleIndex">
    <div class="activityRules">
      <h2>{{title}}</h2>
      <p v-html="rule"></p>
      <!-- <p>1、睡觉就能赚颜值，每晚的20:00至次日2:00可以开启睡觉赚颜值的功能；</p>
      <p>2、每天睡醒后记得来打卡，收取颜值；</p>
      <p>3、睡醒后，在20:00前未打卡，将无法收取颜值，需客户重新开启下一个睡觉打卡；</p>
      <p>快点点击“我要睡了”开启睡觉赚颜值吧～</p> -->
      <div :class="['closeBtn', onTouch ? 'touch' : '']" @touchstart="() => {onTouch = true}" @touchend="() => {onTouch = false}" @click="handleClose">我知道了</div>
    </div>
  </div>
</template>
<script>
import {getActivityRule} from '@/api/request'
export default {
  data() {
    return {
      onTouch: false,
      rule: ''
    };
  },
  props: {
    title: {
      type: String,
      default: '活动规则'
    },
    rules: {
      type: String,
    },
    isShowRule: {
      type: Boolean,
      default: false
    }
  },
  watch: {
    isShowRule (val) {
      console.log(val)
      if (val) {
        if (this.rules) {
          this.rule = this.rules
        } else {
          if (!this.rule) {
            this.getActivityRule()
          }
        }
      }
    }
  },
  methods: {
    handleClose() {
      this.$emit("closeRule");
    },
    getActivityRule () {
      getActivityRule({

      }).then(res => {
        console.log(res)
        this.rule = res
      }).catch(e => {
        this.$toastMessage({message: e.message, time: 3000})
      })
    }
  }
};
</script>
<style lang="less" scoped>
.activityRules {
  width: 5.1rem;
  padding: 0.55rem;
  border-radius: 0.2rem;
  background: #fff;
  color: #383838;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 999;
  h2 {
    font-size: 0.36rem;
    text-align: center;
  }

  p {
    font-size: 0.26rem;
    line-height: 0.4rem;
    margin-top: 0.3rem;
  }
  .closeBtn {
    width: 5rem;
    height: 0.74rem;
    border-radius: 0.37rem;
    background: #7b2c3f;
    font-size: 0.3rem;
    text-align: center;
    line-height: 0.74rem;
    color: #fff;
    margin: 0.5rem auto 0;
  }
  .touch {
    background: #5a2733;
  }
}
</style>